<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>19 R | Glossary</title>
<meta name="author" content="psyTeachR Team">
<meta name="description" content="19.1 R markdown The R-specific version of markdown: a way to specify formatting, such as headers, paragraphs, lists, bolding, and links, as well as code blocks and inline code. An R markdown file...">
<meta name="generator" content="bookdown 0.24 with bs4_book()">
<meta property="og:title" content="19 R | Glossary">
<meta property="og:type" content="book">
<meta property="og:url" content="https://psyteachr.github.io/glossary/r.html">
<meta property="og:image" content="https://psyteachr.github.io/glossary/images/logos/logo.png">
<meta property="og:description" content="19.1 R markdown The R-specific version of markdown: a way to specify formatting, such as headers, paragraphs, lists, bolding, and links, as well as code blocks and inline code. An R markdown file...">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="19 R | Glossary">
<meta name="twitter:description" content="19.1 R markdown The R-specific version of markdown: a way to specify formatting, such as headers, paragraphs, lists, bolding, and links, as well as code blocks and inline code. An R markdown file...">
<meta name="twitter:image" content="https://psyteachr.github.io/glossary/images/logos/logo.png">
<!-- JS --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://kit.fontawesome.com/6ecbd6c532.js" crossorigin="anonymous"></script><script src="libs/header-attrs-2.11/header-attrs.js"></script><script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="libs/bootstrap-4.6.0/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-4.6.0/bootstrap.bundle.min.js"></script><script src="libs/bs3compat-0.3.1/transition.js"></script><script src="libs/bs3compat-0.3.1/tabs.js"></script><script src="libs/bs3compat-0.3.1/bs3compat.js"></script><link href="libs/bs4_book-1.0.0/bs4_book.css" rel="stylesheet">
<script src="libs/bs4_book-1.0.0/bs4_book.js"></script><script src="libs/kePrint-0.0.1/kePrint.js"></script><link href="libs/lightable-0.0.1/lightable.css" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics --><script async src="https://www.googletagmanager.com/gtag/js?id=G-6NP3MF25W3"></script><script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-6NP3MF25W3');
    </script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- CSS --><link rel="stylesheet" href="include/psyteachr.css">
<link rel="stylesheet" href="include/webex.css">
<link rel="stylesheet" href="include/style.css">
</head>
<body data-spy="scroll" data-target="#toc">

<div class="container-fluid">
<div class="row">
  <header class="col-sm-12 col-lg-3 sidebar sidebar-book"><a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>

    <div class="d-flex align-items-start justify-content-between">
      <h1>
        <a href="index.html" title="">Glossary</a>
      </h1>
      <button class="btn btn-outline-primary d-lg-none ml-2 mt-1" type="button" data-toggle="collapse" data-target="#main-nav" aria-expanded="true" aria-controls="main-nav"><i class="fas fa-bars"></i><span class="sr-only">Show table of contents</span></button>
    </div>

    <div id="main-nav" class="collapse-lg">
      <form role="search">
        <input id="search" class="form-control" type="search" placeholder="Search" aria-label="Search">
</form>

      <nav aria-label="Table of contents"><h2>Table of contents</h2>
        <ul class="book-toc list-unstyled">
<li><a class="" href="index.html">Overview</a></li>
<li><a class="" href="symbols.html"><span class="header-section-number">1</span> Symbols</a></li>
<li><a class="" href="a.html"><span class="header-section-number">2</span> A</a></li>
<li><a class="" href="b.html"><span class="header-section-number">3</span> B</a></li>
<li><a class="" href="c.html"><span class="header-section-number">4</span> C</a></li>
<li><a class="" href="d.html"><span class="header-section-number">5</span> D</a></li>
<li><a class="" href="e.html"><span class="header-section-number">6</span> E</a></li>
<li><a class="" href="f.html"><span class="header-section-number">7</span> F</a></li>
<li><a class="" href="g.html"><span class="header-section-number">8</span> G</a></li>
<li><a class="" href="h.html"><span class="header-section-number">9</span> H</a></li>
<li><a class="" href="i.html"><span class="header-section-number">10</span> I</a></li>
<li><a class="" href="j.html"><span class="header-section-number">11</span> J</a></li>
<li><a class="" href="k.html"><span class="header-section-number">12</span> K</a></li>
<li><a class="" href="l.html"><span class="header-section-number">13</span> L</a></li>
<li><a class="" href="m.html"><span class="header-section-number">14</span> M</a></li>
<li><a class="" href="n.html"><span class="header-section-number">15</span> N</a></li>
<li><a class="" href="o.html"><span class="header-section-number">16</span> O</a></li>
<li><a class="" href="p.html"><span class="header-section-number">17</span> P</a></li>
<li><a class="" href="q.html"><span class="header-section-number">18</span> Q</a></li>
<li><a class="active" href="r.html"><span class="header-section-number">19</span> R</a></li>
<li><a class="" href="s.html"><span class="header-section-number">20</span> S</a></li>
<li><a class="" href="t.html"><span class="header-section-number">21</span> T</a></li>
<li><a class="" href="u.html"><span class="header-section-number">22</span> U</a></li>
<li><a class="" href="v.html"><span class="header-section-number">23</span> V</a></li>
<li><a class="" href="w.html"><span class="header-section-number">24</span> W</a></li>
<li><a class="" href="x.html"><span class="header-section-number">25</span> X</a></li>
<li><a class="" href="y.html"><span class="header-section-number">26</span> Y</a></li>
<li><a class="" href="z.html"><span class="header-section-number">27</span> Z</a></li>
</ul>

        <div class="book-extra">
          <p><a id="book-repo" href="https://github.com/psyteachr/glossary">View book source <i class="fab fa-github"></i></a></p>
        </div>
      </nav>
</div>
  </header><main class="col-sm-12 col-md-9 col-lg-7" id="content"><div id="r" class="section level1" number="19">
<h1>
<span class="header-section-number">19</span> R<a class="anchor" aria-label="anchor" href="#r"><i class="fas fa-link"></i></a>
</h1>

<div id="r-markdown" class="section level2" number="19.1">
<h2>
<span class="header-section-number">19.1</span> R markdown<a class="anchor" aria-label="anchor" href="#r-markdown"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>The R-specific version of markdown: a way to specify formatting, such as headers, paragraphs, lists, bolding, and links, as well as code blocks and inline code.</dfn></p>
<p>An R markdown file starts with a <a href="y.html#yaml">YAML</a> header that usually contains the title, author, and output type.</p>
<pre><code>---
title: "Analysis Plan Template"
author: "School of Psychology, University of Glasgow"
output: html_document
---</code></pre>
<p>The rest of the file is a mix of <a href="m.html#markdown">markdown</a> and <a href="c.html#chunk">code chunks</a>. Here is an example of two section titles. The first section has an r chunk for loading the packages and the second section has a list of steps.</p>
<pre><code>## Packages used

```{r setup, include = FALSE}
# every time you add a new package, include it in this section
library(tidyverse)
```

## Data Processing

1. load in packages
2. load in dataset
3. Wrangle data into appropriate format for analysis and checks. You might want to reshape the data or combine different values to make a new variable. </code></pre>
<p>Resources:</p>
<ul>
<li><a href="https://rmarkdown.rstudio.com/lesson-1.html">Introduction to R Markdown</a></li>
<li><a href="https://www.rstudio.com/wp-content/uploads/2016/03/rmarkdown-cheatsheet-2.0.pdf">R Markdown Cheatsheet</a></li>
<li><a href="https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf">R Markdown Reference</a></li>
</ul>
</div>
<div id="r-squared" class="section level2" number="19.2">
<h2>
<span class="header-section-number">19.2</span> R-squared<a class="anchor" aria-label="anchor" href="#r-squared"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A statistic that represents the proportion of the <a href="v.html#variance">variance</a> for a <a href="d.html#dependent-variable">dependent variable</a> explained by the <a href="p.html#predictor-variable">predictor variable(s)</a> in a <a href="g.html#general-linear-model">linear model</a>.</dfn></p>
<p>Let's simulate some data</p>
<div class="sourceCode" id="cb181"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># simulate some data</span>
<span class="fu"><a href="https://rdrr.io/r/base/Random.html">set.seed</a></span><span class="op">(</span><span class="fl">8675309</span><span class="op">)</span>

<span class="va">n</span> <span class="op">&lt;-</span> <span class="fl">100</span>
<span class="va">intercept</span> <span class="op">&lt;-</span> <span class="fl">10</span>
<span class="va">effect</span> <span class="op">&lt;-</span> <span class="fl">0.5</span>
<span class="va">error_sd</span> <span class="op">&lt;-</span> <span class="fl">2</span>

<span class="va">dat</span> <span class="op">&lt;-</span> <span class="fu">tibble</span><span class="fu">::</span><span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html">tibble</a></span><span class="op">(</span>
  predictor <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html">rnorm</a></span><span class="op">(</span><span class="va">n</span>, <span class="fl">0</span>, <span class="fl">1</span><span class="op">)</span>,
  error <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html">rnorm</a></span><span class="op">(</span><span class="va">n</span>, <span class="fl">0</span>, <span class="va">error_sd</span><span class="op">)</span>,
  dv <span class="op">=</span> <span class="va">intercept</span> <span class="op">+</span> <span class="op">(</span><span class="va">effect</span> <span class="op">*</span> <span class="va">predictor</span><span class="op">)</span> <span class="op">+</span> <span class="va">error</span>
<span class="op">)</span></code></pre></div>
<p>Analyse the data with a linear model and use the <code><a href="https://rdrr.io/r/base/summary.html">summary()</a></code> function to view the R-squared values.</p>
<div class="sourceCode" id="cb182"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">model</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/lm.html">lm</a></span><span class="op">(</span><span class="va">dv</span> <span class="op">~</span> <span class="va">predictor</span>, <span class="va">dat</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/summary.html">summary</a></span><span class="op">(</span><span class="va">model</span><span class="op">)</span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Call:</span>
<span class="co">#&gt; lm(formula = dv ~ predictor, data = dat)</span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Residuals:</span>
<span class="co">#&gt;     Min      1Q  Median      3Q     Max </span>
<span class="co">#&gt; -5.0692 -1.4106  0.2447  1.4562  3.9263 </span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Coefficients:</span>
<span class="co">#&gt;             Estimate Std. Error t value Pr(&gt;|t|)    </span>
<span class="co">#&gt; (Intercept)   9.8913     0.1991  49.677  &lt; 2e-16 ***</span>
<span class="co">#&gt; predictor     0.6361     0.2150   2.958  0.00388 ** </span>
<span class="co">#&gt; ---</span>
<span class="co">#&gt; Signif. codes:  0 '***' 1e-03 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Residual standard error: 1.988 on 98 degrees of freedom</span>
<span class="co">#&gt; Multiple R-squared:  0.08198,    Adjusted R-squared:  0.07261 </span>
<span class="co">#&gt; F-statistic: 8.752 on 1 and 98 DF,  p-value: 0.003877</span></code></pre></div>
<p><a href="a.html#adjusted-r-squared">Adjusted R-squared</a> is a modified version of R-squared adjusted for the number of predictors in the model. You can extract the R-squared and adjusted R-squared values from the model summary.</p>
<div class="sourceCode" id="cb183"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/summary.html">summary</a></span><span class="op">(</span><span class="va">model</span><span class="op">)</span><span class="op">$</span><span class="va">r.squared</span>
<span class="co">#&gt; [1] 0.08198174</span>
<span class="fu"><a href="https://rdrr.io/r/base/summary.html">summary</a></span><span class="op">(</span><span class="va">model</span><span class="op">)</span><span class="op">$</span><span class="va">adj.r.squared</span>
<span class="co">#&gt; [1] 0.0726142</span></code></pre></div>

</div>
<div id="random-effect" class="section level2" number="19.3">
<h2>
<span class="header-section-number">19.3</span> random effect<a class="anchor" aria-label="anchor" href="#random-effect"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>An effect associated with an individual sampling unit, usually represented by an offset from a fixed effect.</dfn></p>
<p><strong>Example:</strong> If the grand mean response time in a population is 600 milliseconds, that number represents the typical value. The mean response time for an individual subject <span class="math inline">\(s\)</span> can be represented as an offset (<a href="d.html#deviation-score">deviation</a>) from that value. For example, if subject <span class="math inline">\(s\)</span> has a mean reaction time of 650 ms, that would imply a random effect for that subject of +50 ms.</p>
<p>Unlike <a href="f.html#fixed%20effect">fixed effects</a>, we expect the underlying random effects to change from experiment to experiment as the sampling units (e.g., subjects) change.</p>
<p>In a mixed effects model, you can get a table of just the random effects with the code below:</p>
<div class="sourceCode" id="cb184"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">model</span> <span class="op">&lt;-</span> <span class="fu">afex</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/lmerTest/man/lmer.html">lmer</a></span><span class="op">(</span>
  <span class="va">rating</span> <span class="op">~</span> <span class="va">rater_age</span> <span class="op">*</span> <span class="va">face_age</span> <span class="op">+</span> <span class="co"># fixed effects</span>
  <span class="op">(</span><span class="fl">1</span> <span class="op">|</span> <span class="va">rater_id</span><span class="op">)</span> <span class="op">+</span> <span class="op">(</span><span class="fl">1</span> <span class="op">|</span> <span class="va">face_id</span><span class="op">)</span>, <span class="co"># random effects</span>
  data <span class="op">=</span> <span class="fu">faux</span><span class="fu">::</span><span class="va"><a href="https://rdrr.io/pkg/faux/man/fr4.html">fr4</a></span>
<span class="op">)</span>

<span class="fu">broom.mixed</span><span class="fu">::</span><span class="fu"><a href="https://generics.r-lib.org/reference/tidy.html">tidy</a></span><span class="op">(</span><span class="va">model</span>, effects <span class="op">=</span> <span class="st">"ran_pars"</span><span class="op">)</span></code></pre></div>
<div class="kable-table">
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:left;">
effect
</th>
<th style="text-align:left;">
group
</th>
<th style="text-align:left;">
term
</th>
<th style="text-align:right;">
estimate
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
ran_pars
</td>
<td style="text-align:left;">
face_id
</td>
<td style="text-align:left;">
sd__(Intercept)
</td>
<td style="text-align:right;">
0.6040734
</td>
</tr>
<tr>
<td style="text-align:left;">
ran_pars
</td>
<td style="text-align:left;">
rater_id
</td>
<td style="text-align:left;">
sd__(Intercept)
</td>
<td style="text-align:right;">
0.9144817
</td>
</tr>
<tr>
<td style="text-align:left;">
ran_pars
</td>
<td style="text-align:left;">
Residual
</td>
<td style="text-align:left;">
sd__Observation
</td>
<td style="text-align:right;">
1.0434014
</td>
</tr>
</tbody>
</table></div>
</div>

</div>
<div id="random-factor" class="section level2" number="19.4">
<h2>
<span class="header-section-number">19.4</span> random factor<a class="anchor" aria-label="anchor" href="#random-factor"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A <a href="f.html#factor">factor</a> whose <a href="l.html#level">levels</a> are taken to represent a proper subset of a population of interest, typically because the observed levels are the result of sampling.</dfn></p>
<p>If you perform a study where the population of interest is "undergraduates at the University of Glasgow", you are very unlikely to obtain data from all approximately 20,000 undergraduate students. Instead, you would likely obtain a (hopefully random) sample of undergraduates, with each undergraduate forming a single 'level' of the 'subject' factor. By treating 'subject' as random rather than fixed in your analysis, you will obtain parameter estimates that are closer to the true population values.</p>
<p>Random factors are usually contrasted with <a href="f.html#fixed-factor">fixed factors</a>, whose levels are assumed to represent all the levels of interest in a population.</p>

</div>
<div id="random-seed" class="section level2" number="19.5">
<h2>
<span class="header-section-number">19.5</span> random seed<a class="anchor" aria-label="anchor" href="#random-seed"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A value used to set the initial state of a random number generator.</dfn></p>
<p>Random seeds are used in random number generation. Each time you generate a random number, the number you get depends on the state of the underlying random number generator. If you set this state to a known value, you will get the same random numbers in the same order.</p>
<p>Random seeds are used to make processes that involve random values reproducible. In R, you can set a random seed using the <code><a href="https://rdrr.io/r/base/Random.html">set.seed()</a></code> function. If you put <code><a href="https://rdrr.io/r/base/Random.html">set.seed()</a></code> at the start of your script, you will get the same output every time.</p>

</div>
<div id="reactivity" class="section level2" number="19.6">
<h2>
<span class="header-section-number">19.6</span> reactivity<a class="anchor" aria-label="anchor" href="#reactivity"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>Changes in a <a href="s.html#shiny">Shiny</a> app that occur in response to user input.</dfn></p>
<p>Reactive features of your <a href="u.html#ui">UI</a> are rendered in the <a href="s.html#server">server</a>.</p>

</div>
<div id="readme" class="section level2" number="19.7">
<h2>
<span class="header-section-number">19.7</span> README<a class="anchor" aria-label="anchor" href="#readme"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A text file in the base directory of a project that describes the project.</dfn></p>

</div>
<div id="relative-path" class="section level2" number="19.8">
<h2>
<span class="header-section-number">19.8</span> relative path<a class="anchor" aria-label="anchor" href="#relative-path"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>The location of a file in relation to the working directory.</dfn></p>
<p>For example, if your <a href="w.html#working-directory">working directory</a> is <code>/Users/me/study/</code> and you want to refer to a file at <code>/Users/me/study/data/faces.csv</code>, the relative path is <code>data/faces.csv</code>. Use <code>../</code> to move up one directory.</p>
<div class="sourceCode" id="cb185"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># the working directory: /Users/me/study/</span>

<span class="co"># read a file inside the wd: /Users/me/study/data/faces.csv</span>
<span class="va">qdat</span> <span class="op">&lt;-</span> <span class="fu">readr</span><span class="fu">::</span><span class="fu"><a href="https://readr.tidyverse.org/reference/read_delim.html">read_csv</a></span><span class="op">(</span><span class="st">"data/faces.csv"</span><span class="op">)</span>

<span class="co"># read a file outside the wd: /Users/me/other_study/data/exp.csv</span>
<span class="va">xdat</span> <span class="op">&lt;-</span> <span class="fu">readr</span><span class="fu">::</span><span class="fu"><a href="https://readr.tidyverse.org/reference/read_delim.html">read_csv</a></span><span class="op">(</span><span class="st">"../other_study/data/exp.csv"</span><span class="op">)</span></code></pre></div>
<p>Make sure you always use relative paths in an <a href="r.html#r-markdown">R Markdown</a> document, which automatically sets the working directory to the directory that contains the .Rmd file.</p>
<p>Contrast with <a href="a.html#absolute-path">absolute path</a>.</p>

</div>
<div id="render" class="section level2" number="19.9">
<h2>
<span class="header-section-number">19.9</span> render<a class="anchor" aria-label="anchor" href="#render"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>To create a file (usually an image or PDF) or <a href="w.html#widget">widget</a> from source code</dfn></p>
<p>In the context of <a href="s.html#shiny">Shiny</a> apps, render usually means to create the <a href="h.html#html">HTML</a> to display in a <a href="r.html#reactivity">reactive</a> output from code in the <a href="s.html#server">server</a> section.</p>
<p>In the context of <a href="r.html#r-markdown">R Markdown</a> files, <a href="k.html#knit">knit</a>, render and <a href="c.html#compile">compile</a> tend to be used interchangeably.</p>

</div>
<div id="repeated-measures" class="section level2" number="19.10">
<h2>
<span class="header-section-number">19.10</span> repeated measures<a class="anchor" aria-label="anchor" href="#repeated-measures"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A dataset has repeated measures if there are multiple measurements taken on the same <a href="v.html#variable">variable</a> for individual <a href="s.html#sampling%20unit">sampling units</a>.</dfn></p>
<p>See also <a href="m.html#multilevel">multilevel</a>.</p>

</div>
<div id="replicability" class="section level2" number="19.11">
<h2>
<span class="header-section-number">19.11</span> replicability<a class="anchor" aria-label="anchor" href="#replicability"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>The extent to which the findings of a study can be repeated with new samples from the same population.</dfn></p>
<p>Alternatively, a scientific claim is replicable if it is supported by new data (<a href="https://doi.org/10.7554/eLife.71601">Errington et al., 2021</a>).</p>
<p>See also <a href="r.html#reproducibility">reproducibility</a>.</p>
<p>The aim of replicating a study is test the underlying theoretical process, estimate the average effect size, and test whether you can observe the effect independent of the original researchers by recreating a study's methods as closely as possible (<a href="https://www.sciencedirect.com/science/article/pii/S0022103113001819">Brandt et al., 2014</a>).</p>
<p>There is not a clear definition for a successful replication, but there are some common markers (<a href="https://doi.org/10.7554/eLife.71601">Errington et al., 2021</a>):</p>
<ul>
<li>Is the replication effect in the same direction as the original study?</li>
<li>Is the replication effect and statistical significance in the same direction as the original study?</li>
<li>Is the effect size from the original study in the confidence interval of the replication?</li>
<li>Is the effect size from the replication study in the confidence interval of the original?</li>
<li>Is the effect size from the replication smaller or equal to the effect size from the original study?</li>
</ul>
</div>
<div id="reprex" class="section level2" number="19.12">
<h2>
<span class="header-section-number">19.12</span> reprex<a class="anchor" aria-label="anchor" href="#reprex"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A reproducible example that is the smallest, completely self-contained example of your problem or question.</dfn></p>
<p>For example, you may have a question about how to figure out how to select rows that contain the value "test" in a certain column, but it isn't working. It's clearer if you can provide a concrete example, but you don't want to have to type out the whole table you're using or all the code that got you to this point in your script.</p>
<p>You can include a very small table with just the basics or a smaller version of your problem. Make comments at each step about what you expect and what you actually got.</p>
<p>Which version is easier for you to figure out the solution?</p>
<div class="sourceCode" id="cb186"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># this doesn't work</span>
<span class="va">no_test_data</span> <span class="op">&lt;-</span> <span class="va">data</span> <span class="op">%&gt;%</span>
  <span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op">(</span><span class="op">!</span><span class="fu">str_detect</span><span class="op">(</span><span class="va">type</span>, <span class="st">"test"</span><span class="op">)</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb187"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># with a minimal example table</span>
<span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://tibble.tidyverse.org/reference/tribble.html">tribble</a></span><span class="op">(</span>
  <span class="op">~</span><span class="va">id</span>, <span class="op">~</span><span class="va">type</span>, <span class="op">~</span><span class="va">x</span>,
  <span class="fl">1</span>, <span class="st">"test"</span>, <span class="fl">12</span>,
  <span class="fl">2</span>, <span class="st">"testosterone"</span>, <span class="fl">15</span>,
  <span class="fl">3</span>, <span class="st">"estrogen"</span>, <span class="fl">10</span>
<span class="op">)</span>

<span class="co"># this should keep IDs 2 and 3, but removes ID 2</span>
<span class="va">no_test_data</span> <span class="op">&lt;-</span> <span class="va">data</span> <span class="op">%&gt;%</span>
  <span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op">(</span><span class="op">!</span><span class="fu">str_detect</span><span class="op">(</span><span class="va">type</span>, <span class="st">"test"</span><span class="op">)</span><span class="op">)</span></code></pre></div>
<p>One of the big benefits to creating a reprex is that you often solve your own problem while you're trying to break it down to explain to someone else.</p>
<p>If you really want to go down the rabbit hole, you can create a reproducible example using the <a href="https://www.tidyverse.org/help/#reprex">reprex</a> package from tidyverse.</p>

</div>
<div id="reproducibility" class="section level2" number="19.13">
<h2>
<span class="header-section-number">19.13</span> reproducibility<a class="anchor" aria-label="anchor" href="#reproducibility"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>The extent to which the findings of a study can be repeated in some other context</dfn></p>
<p>Reproducibility can be either with new samples from the same population (<a href="r.html#replicability">replicability</a>) or with the same raw data but analyzed by different researchers or by the same researchers on a different occasion (<a href="c.html#computational-reproducibility">computational</a> or analytical reproducibility).</p>

</div>
<div id="reproducible-research" class="section level2" number="19.14">
<h2>
<span class="header-section-number">19.14</span> reproducible research<a class="anchor" aria-label="anchor" href="#reproducible-research"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>Research that documents all of the steps between raw data and results in a way that can be verified.</dfn></p>

</div>
<div id="residual" class="section level2" number="19.15">
<h2>
<span class="header-section-number">19.15</span> residual<a class="anchor" aria-label="anchor" href="#residual"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>Defined as the deviation of an observation from a model's expected value.</dfn></p>
<p>Mathematically, the residual is defined as the observed value minus the model's <a href="f.html#fitted-value">fitted value</a> for that observation.</p>
<p>For example, the linear model <span class="math inline">\(\hat{Y_i} = 3 + 2 X_i\)</span> predicts a value of <span class="math inline">\(\hat{Y}_i = 7\)</span> for <span class="math inline">\(X_i = 2\)</span>. If you happen to have observed <span class="math inline">\(Y_i = 8\)</span> for observation <span class="math inline">\(i\)</span>, then the residual for that observation would be <span class="math inline">\(Y_i - \hat{Y}_i = 8 - 7 = 1\)</span>.</p>
<p>A related but slightly different notion is <a href="e.html#error">error</a>.</p>

</div>
<div id="response-variable" class="section level2" number="19.16">
<h2>
<span class="header-section-number">19.16</span> response variable<a class="anchor" aria-label="anchor" href="#response-variable"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A variable (in a regression) whose value is assumed to be influenced by one or more predictor variables.</dfn></p>
<p>In an experimental context, the response variable is often referred to as the <a href="d.html#dependent-variable">dependent variable</a>.</p>

</div>
<div id="right_join" class="section level2" number="19.17">
<h2>
<span class="header-section-number">19.17</span> right_join<a class="anchor" aria-label="anchor" href="#right_join"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A <a href="m.html#mutating-joins">mutating join</a> that keeps all the data from the second (right) table and joins anything that matches from the first (left) table.</dfn></p>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:right-join"></span>
<img src="images/joins/right_join.png" alt="Right Join" width="100%"><p class="caption">
Figure 19.1: Right Join
</p>
</div>
<div class="sourceCode" id="cb188"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">X</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html">tibble</a></span><span class="op">(</span>
  id <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">5</span>,
  x <span class="op">=</span> <span class="va">LETTERS</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">5</span><span class="op">]</span>
<span class="op">)</span>

<span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html">tibble</a></span><span class="op">(</span>
  id <span class="op">=</span> <span class="fl">2</span><span class="op">:</span><span class="fl">6</span>,
  y <span class="op">=</span> <span class="va">LETTERS</span><span class="op">[</span><span class="fl">22</span><span class="op">:</span><span class="fl">26</span><span class="op">]</span>
<span class="op">)</span></code></pre></div>
<div class="inline-table"><table class="table table-sm">
<tr>
<th>
Table X
</th>
<th>
Table Y
</th>

</tr>
<tr>
<td>
<table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
x
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
A
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
B
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
C
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
D
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
<td style="text-align:left;">
E
</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
y
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
V
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
W
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
X
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
<td style="text-align:left;">
Y
</td>
</tr>
<tr>
<td style="text-align:right;">
6
</td>
<td style="text-align:left;">
Z
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table></div>
<p>If there is no matching data in the left table for a row, the values are set to <a href="n.html#na">NA</a>.</p>
<div class="sourceCode" id="cb189"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># a is the right table</span>
<span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate-joins.html">right_join</a></span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span>, by <span class="op">=</span> <span class="st">"id"</span><span class="op">)</span></code></pre></div>
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
x.x
</th>
<th style="text-align:left;">
y
</th>
<th style="text-align:left;">
x.y
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
D
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
E
</td>
</tr>
<tr>
<td style="text-align:right;">
6
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
F
</td>
</tr>
</tbody>
</table></div>
<p>Order is important for right joins.</p>
<div class="sourceCode" id="cb190"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># b is the right table</span>
<span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate-joins.html">right_join</a></span><span class="op">(</span><span class="va">b</span>, <span class="va">a</span>, by <span class="op">=</span> <span class="st">"id"</span><span class="op">)</span></code></pre></div>
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:left;">
x.x
</th>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
x.y
</th>
<th style="text-align:left;">
y
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
NA
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
A
</td>
<td style="text-align:left;">
TRUE
</td>
</tr>
<tr>
<td style="text-align:left;">
NA
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
B
</td>
<td style="text-align:left;">
TRUE
</td>
</tr>
<tr>
<td style="text-align:left;">
NA
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
C
</td>
<td style="text-align:left;">
FALSE
</td>
</tr>
</tbody>
</table></div>
<p>See <a href="j.html#joins">joins</a> for other types of joins and further resources.</p>

</div>
<div id="rstudio" class="section level2" number="19.18">
<h2>
<span class="header-section-number">19.18</span> RStudio<a class="anchor" aria-label="anchor" href="#rstudio"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>An integrated development environment (<a href="i.html#ide">IDE</a>) that helps you process R code.</dfn></p>
<p>Download RStudio at <a href="https://rstudio.com/" class="uri">https://rstudio.com/</a></p>

</div>
</div>
<script>

/* update total correct if #webex-total_correct exists */
update_total_correct = function() {
  console.log("webex: update total_correct");

  if (t = document.getElementById("webex-total_correct")) {
    var correct = document.getElementsByClassName("webex-correct").length;
    var solvemes = document.getElementsByClassName("webex-solveme").length;
    var radiogroups = document.getElementsByClassName("webex-radiogroup").length;
    var selects = document.getElementsByClassName("webex-select").length;
    
    t.innerHTML = correct + " of " + (solvemes + radiogroups + selects) + " correct";
  }
}

/* webex-solution button toggling function */
b_func = function() {
  console.log("webex: toggle hide");
  
  var cl = this.parentElement.classList;
  if (cl.contains('open')) {
    cl.remove("open");
  } else {
    cl.add("open");
  }
}

/* function for checking solveme answers */
solveme_func = function(e) {
  console.log("webex: check solveme");

  var real_answers = JSON.parse(this.dataset.answer);
  var my_answer = this.value;
  var cl = this.classList;
  if (cl.contains("ignorecase")) {
    my_answer = my_answer.toLowerCase();
  }
  if (cl.contains("nospaces")) {
    my_answer = my_answer.replace(/ /g, "")
  }

  if (my_answer == "") {
    cl.remove("webex-correct");
    cl.remove("webex-incorrect");
  } else if (real_answers.includes(my_answer)) {
    cl.add("webex-correct");
    cl.remove("webex-incorrect");
  } else {
    cl.add("webex-incorrect");
    cl.remove("webex-correct");
  }

  // match numeric answers within a specified tolerance
  if(this.dataset.tol > 0){
    var tol = JSON.parse(this.dataset.tol);
    var matches = real_answers.map(x => Math.abs(x - my_answer) < tol)
    if (matches.reduce((a, b) => a + b, 0) > 0) {
      cl.add("webex-correct");
    } else {
      cl.remove("webex-correct");
    }
  }

  // added regex bit
  if (cl.contains("regex")){
    answer_regex = RegExp(real_answers.join("|"))
    if (answer_regex.test(my_answer)) {
      cl.add("webex-correct");
    }
  }

  update_total_correct();
}

/* function for checking select answers */
select_func = function(e) {
  console.log("webex: check select");
  
  var cl = this.classList
  
  /* add style */
  cl.remove("webex-incorrect");
  cl.remove("webex-correct");
  if (this.value == "answer") {
    cl.add("webex-correct");
  } else if (this.value != "blank") {
    cl.add("webex-incorrect");
  }
  
  update_total_correct();
}

/* function for checking radiogroups answers */
radiogroups_func = function(e) {
  console.log("webex: check radiogroups");

  var checked_button = document.querySelector('input[name=' + this.id + ']:checked');
  var cl = checked_button.parentElement.classList;
  var labels = checked_button.parentElement.parentElement.children;
  
  /* get rid of styles */
  for (i = 0; i < labels.length; i++) {
    labels[i].classList.remove("webex-incorrect");
    labels[i].classList.remove("webex-correct");
  }
  
  /* add style */
  if (checked_button.value == "answer") {
    cl.add("webex-correct");
  } else {
    cl.add("webex-incorrect");
  }
  
  update_total_correct();
}

window.onload = function() {
  console.log("onload");
  /* set up solution buttons */
  var buttons = document.getElementsByTagName("button");

  for (var i = 0; i < buttons.length; i++) {
    if (buttons[i].parentElement.classList.contains('webex-solution')) {
      buttons[i].onclick = b_func;
    }
  }

  /* set up webex-solveme inputs */
  var solveme = document.getElementsByClassName("webex-solveme");

  for (var i = 0; i < solveme.length; i++) {
    /* make sure input boxes don't auto-anything */
    solveme[i].setAttribute("autocomplete","off");
    solveme[i].setAttribute("autocorrect", "off");
    solveme[i].setAttribute("autocapitalize", "off");
    solveme[i].setAttribute("spellcheck", "false");
    solveme[i].value = "";

    /* adjust answer for ignorecase or nospaces */
    var cl = solveme[i].classList;
    var real_answer = solveme[i].dataset.answer;
    if (cl.contains("ignorecase")) {
      real_answer = real_answer.toLowerCase();
    }
    if (cl.contains("nospaces")) {
      real_answer = real_answer.replace(/ /g, "");
    }
    solveme[i].dataset.answer = real_answer;

    /* attach checking function */
    solveme[i].onkeyup = solveme_func;
    solveme[i].onchange = solveme_func;
  }
  
  /* set up radiogroups */
  var radiogroups = document.getElementsByClassName("webex-radiogroup");
  for (var i = 0; i < radiogroups.length; i++) {
    radiogroups[i].onchange = radiogroups_func;
  }
  
  /* set up selects */
  var selects = document.getElementsByClassName("webex-select");
  for (var i = 0; i < selects.length; i++) {
    selects[i].onchange = select_func;
  }

  update_total_correct();
}

</script><script>
$( document ).ready(function() {
  var cite = ' ';
  var psyteachr = ' <a href="https://psyteachr.github.io/"><img src="images/logos/psyteachr_logo.png" style="height: 31px; color: white;" alt="psyTeachR: Reproducible Research" /></a>';
  var license = ' <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/" target="blank"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png"></a>';

  $("footer div.row div:eq(1) p").html(
    psyteachr + license + cite
  );
  
  $("#toc").appendTo($("#main-nav"));
});
</script><div class="chapter-nav">
<div class="prev"><a href="q.html"><span class="header-section-number">18</span> Q</a></div>
<div class="next"><a href="s.html"><span class="header-section-number">20</span> S</a></div>
</div></main><div class="col-md-3 col-lg-2 d-none d-md-block sidebar sidebar-chapter">
    <nav id="toc" data-toggle="toc" aria-label="On this page"><h2>On this page</h2>
      <ul class="nav navbar-nav">
<li><a class="nav-link" href="#r"><span class="header-section-number">19</span> R</a></li>
<li><a class="nav-link" href="#r-markdown"><span class="header-section-number">19.1</span> R markdown</a></li>
<li><a class="nav-link" href="#r-squared"><span class="header-section-number">19.2</span> R-squared</a></li>
<li><a class="nav-link" href="#random-effect"><span class="header-section-number">19.3</span> random effect</a></li>
<li><a class="nav-link" href="#random-factor"><span class="header-section-number">19.4</span> random factor</a></li>
<li><a class="nav-link" href="#random-seed"><span class="header-section-number">19.5</span> random seed</a></li>
<li><a class="nav-link" href="#reactivity"><span class="header-section-number">19.6</span> reactivity</a></li>
<li><a class="nav-link" href="#readme"><span class="header-section-number">19.7</span> README</a></li>
<li><a class="nav-link" href="#relative-path"><span class="header-section-number">19.8</span> relative path</a></li>
<li><a class="nav-link" href="#render"><span class="header-section-number">19.9</span> render</a></li>
<li><a class="nav-link" href="#repeated-measures"><span class="header-section-number">19.10</span> repeated measures</a></li>
<li><a class="nav-link" href="#replicability"><span class="header-section-number">19.11</span> replicability</a></li>
<li><a class="nav-link" href="#reprex"><span class="header-section-number">19.12</span> reprex</a></li>
<li><a class="nav-link" href="#reproducibility"><span class="header-section-number">19.13</span> reproducibility</a></li>
<li><a class="nav-link" href="#reproducible-research"><span class="header-section-number">19.14</span> reproducible research</a></li>
<li><a class="nav-link" href="#residual"><span class="header-section-number">19.15</span> residual</a></li>
<li><a class="nav-link" href="#response-variable"><span class="header-section-number">19.16</span> response variable</a></li>
<li><a class="nav-link" href="#right_join"><span class="header-section-number">19.17</span> right_join</a></li>
<li><a class="nav-link" href="#rstudio"><span class="header-section-number">19.18</span> RStudio</a></li>
</ul>

      <div class="book-extra">
        <ul class="list-unstyled">
<li><a id="book-source" href="https://github.com/psyteachr/glossary/blob/master/terms/r-.Rmd">View source <i class="fab fa-github"></i></a></li>
          <li><a id="book-edit" href="https://github.com/psyteachr/glossary/edit/master/terms/r-.Rmd">Edit this page <i class="fab fa-github"></i></a></li>
        </ul>
</div>
    </nav>
</div>

</div>
</div> <!-- .container -->

<footer class="bg-primary text-light mt-5"><div class="container"><div class="row">

  <div class="col-12 col-md-6 mt-3">
    <p>"<strong>Glossary</strong>" was written by psyTeachR Team. It was last built on 2022-02-10.</p>
  </div>

  <div class="col-12 col-md-6 mt-3">
    <p>This book was built by the <a class="text-light" href="https://bookdown.org">bookdown</a> R package.</p>
  </div>

</div></div>
</footer><!-- dynamically load mathjax for compatibility with self-contained --><script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script><script type="text/x-mathjax-config">const popovers = document.querySelectorAll('a.footnote-ref[data-toggle="popover"]');
for (let popover of popovers) {
  const div = document.createElement('div');
  div.setAttribute('style', 'position: absolute; top: 0, left:0; width:0, height:0, overflow: hidden; visibility: hidden;');
  div.innerHTML = popover.getAttribute('data-content');

  var has_math = div.querySelector("span.math");
  if (has_math) {
    document.body.appendChild(div);
    MathJax.Hub.Queue(["Typeset", MathJax.Hub, div]);
    MathJax.Hub.Queue(function() {
      popover.setAttribute('data-content', div.innerHTML);
      document.body.removeChild(div);
    })
  }
}
</script>
</body>
</html>
